---
title: "Replication Project Gov 2001"
author: "Kinara Gasper"
date: '2022-10-21'
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library(car)
library(Rmisc)
library(effects)
library(ggplot2)
library(scales)
library(xtable)
library(lubridate)
library(prediction)
library(cowplot)
library(stargazer)
#THEME_PEW
theme_pew <- function(base_size = 12, base_family = "") {
	theme_grey(base_size = base_size, base_family = base_family) %+replace%
		theme(
			axis.line = element_line(colour = "black"),
			axis.text         = element_text(size = rel(0.8)),
			axis.ticks        = element_line(colour = "black"),
			legend.key        = element_rect(colour = "grey80"),
			panel.background = element_blank(),
			panel.border      = element_rect(fill = NA, colour = "grey50"),
			panel.grid.major = element_blank(),
			panel.grid.minor = element_blank(),
			axis.line.x = element_line(color="black", size = .3),
			axis.line.y = element_line(color="black", size = .3),
			strip.background  = element_rect(fill = "grey80", colour = "grey50", size = 0.2)
		)
}
```

Figure 1
```{r}
##################
# Figure 1a
##################

prop.table(table(data$Q42,data$party),2)
data<-data[data$Q8<=3,]
data$party <-factor(data$Q8, labels=c("Democrats","Republicans","Independents"))
df<-as.data.frame(t(prop.table(table(data$Q42,data$party),2)))
names(df)<-c("party","Response","Freq")
df$Response <-factor(df$Response, labels=c("Yes","No","Don't know"))
df$Response <-factor(df$Response,levels(df$Response)[c(3,2,1)])
plot<-ggplot(df, aes(x=party,y=Freq, fill=Response)) +
  scale_y_continuous(labels = percent_format(),expand = c(0, 0)) +
  scale_x_discrete() +
  geom_bar(stat='identity') +
  coord_flip() +
  theme_bw() +
  ylab('A) Assessment of Three Republicans Joining Democrats') +
  xlab('') +
  scale_fill_manual(values=c("#5D5D5D","#BD0B0B","#10A108")) +
  annotate("text", x = c(1:3), y = .1, label = c("57%","55%","50%"),color="white")+
  annotate("text", x = c(1:3), y = .65, label = c("20%","25%","26%"),color="white")+
  annotate("text", x = c(1:3), y = .9, label = c("23%","20%","24%"),color="white")
plot

ggsave(filename="f1a.eps", plot=plot,width=5.5,height=1.5)


##################
# Figure 1b
##################

prop.table(table(data$Q43,data$party),2)
data<-data[data$Q8<=3,]
data$party <-factor(data$Q8, labels=c("Democrats","Republicans","Independents"))
df<-as.data.frame(t(prop.table(table(data$Q43,data$party),2)))
names(df)<-c("party","Response","Freq")
df$Response <-factor(df$Response, labels=c("Yes","No","Don't know"))
df$Response <-factor(df$Response,levels(df$Response)[c(3,2,1)])

plot<-ggplot(df, aes(x=party,y=Freq, fill=Response)) +
  scale_y_continuous(labels = percent_format(),expand = c(0, 0)) +
  scale_x_discrete() +
  geom_bar(stat='identity') +
  coord_flip() +
  theme_bw() +
  ylab('B) Assessment of Three Democrats Joining Republicans') +
  xlab('') +
  scale_fill_manual(values=c("#5D5D5D","#BD0B0B","#10A108")) +
  annotate("text", x = c(1:3), y = .1, label = c("58%","57%","45%"),color="white")+
  annotate("text", x = c(1:3), y = c(.7,.7,.6), label = c("21%","33%","23%"),color="white")+
  annotate("text", x = c(1:3), y = .9, label = c("21%","10%","32%"),color="white")
plot

ggsave(filename="f1b.eps", plot=plot,width=5.5,height=1.5)
```


Figure 2 
```{r}
data<-read.csv("figure1_2.csv",header=T,as.is=T)

#######################
# Generate demographics
#######################

df <- read.csv(text="col1,col2")

#age
df<-rbind(df,cbind("Age",round(mean(data$Q4+18),digits=2)))
#male
df<-rbind(df,cbind("Male",round(prop.table(table(data$Q2))[[1]]*100,digits=2)))
#>college
df<-rbind(df,cbind(">College",round(prop.table(table(data$Q6>=5))[[2]]*100,digits=2)))
#white
df<-rbind(df,cbind("White",round(prop.table(table(data$Q3==1))[[2]]*100,digits=2)))
#ideology
df<-rbind(df,cbind("Ideology",round(mean(data$Q7),digits=2)))
names(df)<-c("Variable"," ")
print(xtable(df),include.rownames=FALSE)

data$defright <- car::recode(data$definition, "0=0;1=1;2=1;else=0")
data$Q41 <- car::recode(data$Q41, "1:2=0;3=1;4:5=3;else=NA")


##################
# Figure 2a
##################


d<-table(data$defright)/nrow(data)
names(d)<-c("Correct","Incorrect")
d<-as.data.frame(d)
t(d)
d$t<-"temp"
plot<-ggplot(d, aes(x=t,y=Freq, fill=Var1)) +
  scale_y_continuous(labels = percent_format(),expand = c(0, 0)) +
  scale_x_discrete(labels="") +
  geom_bar(stat='identity') +
  coord_flip() +
  theme_bw() +
  xlab('') +
  ylab('A) Defintion of Bipartisanship') +
  scale_fill_manual(values=c("#BD0B0B", "#10A108")) +
  theme(legend.position='none') +
  annotate("text", x = 1, y = .5, label = "67% Incorrect",color="white")+
  annotate("text", x = 1, y = .15, label = "33% Correct",color="white")
plot
ggsave(filename="f2a.eps", plot=plot,width=5.5,height=1)

##################
# Figure 2b
##################

d<-prop.table(table(data$Q41))

names(d)<-c("Bad","Neutral","Good")
d<-as.data.frame(d)
t(d)
d$t<-"temp"
plot<-ggplot(d, aes(x=t,y=Freq, fill=Var1)) +
  scale_y_continuous(labels = percent_format(),expand = c(0, 0)) +
  scale_x_discrete(labels="") +
  geom_bar(stat='identity') +
  coord_flip() +
  theme_bw() +
  xlab('') +
  ylab('B) Valence of Bipartisanship') +
  scale_fill_manual(values=c("#BD0B0B", "#5D5D5D","#10A108")) +
  theme(legend.position='none') +
  annotate("text", x = 1, y = .92, label = "16% Bad",color="white")+
  annotate("text", x = 1, y = .6, label = "39% Neutral",color="white") +
  annotate("text", x = 1, y = .15, label = "45% Good",color="white")
plot
ggsave(filename="f2b.eps", plot=plot,width=5.5,height=1)

```

Figure 3 
```{r}
data<-read.csv("figure3.csv",header=T,as.is=T)

library(ggplot2)

data<-data[data$speaker_party=="democrat" | data$speaker_party=="republican",]
data$speaker_party <- factor(data$speaker_party, labels=c("Democrat","Republican"))
data <- data[data$prop<=1,]

midterm <- as.Date(c("1995-01-04","1999-01-06","2003-01-07","2007-01-04","2011-01-05","2015-01-06"))
presidential <- as.Date(c("1997-01-07","2001-01-03","2005-01-04","2009-01-06","2013-01-03","2017-01-03"))

data$speech_date <- as.Date(data$speech_date)

(p <- ggplot(data=data, aes(x=speech_date, y=prop,group=interaction(congress,speaker_party))) + 
		geom_point(alpha=.3, size=.1, aes(color=speaker_party)) +
		stat_smooth(aes(fill = speaker_party,color=speaker_party), span=5) + 
		xlab("Day") + 
		ylab("Proportion of Daily Speeches\nEngaing Bipartisanship")+
		#ggtitle("Calls for Bipartisanship in the US House of Representatives By Party (1995-2018)")+ 
		geom_vline(xintercept = presidential,color="black")+
		geom_vline(xintercept = midterm,color="gray")+ 
		geom_rect(data=data.frame(xmin=as.Date(c("1995-01-01","1997-01-07","2007-01-04","2011-01-06")),
								  xmax=as.Date(c("1997-01-06","2007-01-03","2011-01-05","2017-12-31")),
								  ymin=-Inf,
								  ymax=Inf),
				  aes(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax),
				  fill=c("red","red","blue","red"),alpha=0.25,inherit.aes = FALSE) +
		scale_colour_manual(values=c("blue", "red")) + 
		scale_fill_manual(values=c("blue", "red")) +
		xlim(as.Date("1990-01-01"),as.Date("2017-12-31")) +
		theme_pew()+ 
		theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
		theme(legend.position = "none") +
		coord_cartesian(ylim=c(0,.3), xlim=c(as.Date("1996-01-01"),as.Date("2016-12-31"))) +
		scale_x_date(date_breaks = "1 year", date_labels = "%Y"))

p
ggsave(filename="f3.pdf", plot=p,width=10,height=4)
```

Figure 4
```{r}
data<-read.csv("figure4.csv",header=T,as.is=T)

data<-data[data$party_code==200 |data$party_code==100,]
data <- data[data$chamber=="House",]
#there is no column labeled 'total' in data, so there is no reason to make
#the variables that are NA equal to 0 
data$total[is.na(data$total)] <-0
data$Party <- factor(data$party_code, labels=c("Democrat","Republican"))

data$nominate_congress <- as.factor(data$nominate_congress)
data <-data[!is.na(data$nominate_congress),]

library(dplyr)
a <- data %>%
	group_by(nominate_congress) %>%
	summarise(mean=mean(prop))

p<-ggplot(data, aes(x=nominate_dim1, y=prop,group=Party, weight=total)) + 
	theme_bw() + 
	xlab("") + 
	ylab("Proportion of Speeches\nEngaging Bipartisanship")+
	geom_point(alpha = .05, aes(size=total, color=Party))  + 
	stat_smooth(method="loess",aes(fill = Party,color=Party))  + 
	theme_pew() +
	scale_colour_manual(values=c("blue","red")) + 
	scale_fill_manual(values=c("blue","red"))+ 
	facet_wrap(~ nominate_congress, ncol = 2) + 
	theme(legend.position = "none") + 
	geom_vline(xintercept = c(0),color="black") +
	geom_hline(aes(yintercept=mean), data=a, color="gray") 
p

ggsave(filename="f4.pdf", plot=p,width=6,height=8)
```
# CHECK COMMENT ABOVE BECAUSE PLOT CANNOT BE MADE UNTIL ISSUE IS FIXED

Figure 5 
```{r}
summaryData<-read.csv("figure5.csv",header=T,as.is=T)

#################
# Figure 5
#################

p <- ggplot(summaryData, aes(x=names, y=modelcoef, ymin=ylo, ymax=yhi)) + 
	geom_pointrange(colour=ifelse(summaryData$ylo < 0 & summaryData$yhi > 0, "red", "blue")) + 
	theme_pew()  + 
	geom_hline(aes(yintercept=0), lty=2) + 
	coord_flip() + 
	ylab("Percent of speeches referencing bipartisanship\n(95% CIs, Clustered Robust Standard Errors,\nCongress Fixed Effects)") + 
	xlab("") #+ ggtitle("Estimated Change in Proportion of Floor Speeches with Bipartisan Rhetoric") 
p
ggsave("f5.eps",p, width=6, height=2)

```

Figure 6
```{r}
#################
# Figure 6
#################
data<-read.csv("figure6.csv",header=T,as.is=T)

p <- ggplot(data, aes(x=names, y=modelcoef, ymin=ylo, ymax=yhi)) + 
	geom_pointrange(colour=ifelse(data$ylo < 0 & data$yhi > 0, "red", "blue")) + 
	theme_pew()  + 
	geom_hline(aes(yintercept=0), lty=2) + 
	coord_flip() + 
	ylab("Percent of speeches referencing bipartisanship\n(95% CIs, Clustered Robust Standard Errors,\nCongress Fixed Effects)") + 
	xlab("") #+ ggtitle("Estimated Change in Proportion of Floor Speeches with Bipartisan Rhetoric") 
p
ggsave("f6.eps",p, width=6, height=2)
```

Figure 7 
```{r}
data<-read.csv("figure7.csv",header=T,as.is=T)

x <- lm(prop~defecting+congress, data=data, weights=n)
summary(x)

install.packages("prediction")
library("prediction")
library(ggplot2)
a<-summary(prediction(x, at = list(defecting = seq(0,1,.1))))

votes <- ggplot(data=a, aes(y=Prediction, x=`at(defecting)`)) +
	geom_line() +
	geom_ribbon(aes(ymin=lower,ymax=upper),alpha=0.3) +
	xlab("Proportion of Speeches on a Bill Engaging Bipartisanship\n(95% CIs, Congress Fixed Effects)") +
	ylab("Proportion of Members Defecting\nfrom Their Party on a Bill")+
	theme_pew()+ 
	theme(legend.position = "none") +
	ylim(0,1)
votes
ggsave("f7.pdf",votes,width=4, height=4)

```

Figure 9
```{r}
library("stargazer")
library("xtable")
library("plyr")

data<-read.csv("figure9.csv",header=T,as.is=T)
# pid3
data$pid3 <-NA
data$pid3[data$Q4.3==1] =1
data$pid3[data$Q4.3==2] =2
data$pid3[data$Q4.3>=3] =3
data$pid3 = factor(data$pid3 , labels=c("Republican","Democrat","Independent"))
prop.table(table(data$pid3))

df <- read.csv(text="col1,col2")

#age
df<-rbind(df,cbind("Age",round(mean(data$Q1.4+17),digits=2)))
#male
df<-rbind(df,cbind("Male",round(prop.table(table(data$Q1.5))[[1]]*100,digits=2)))
#>college
df<-rbind(df,cbind(">College",round(prop.table(table(data$Q1.6>=7))[[2]]*100,digits=2)))
#white
df<-rbind(df,cbind("White",round(prop.table(table(data$Q1.8==4))[[2]]*100,digits=2)))
#ideology
df<-rbind(df,cbind("Ideology",round(mean(data$Q4.8),digits=2)))
names(df)<-c("Variable"," ")
print(xtable(df),include.rownames=FALSE)


data$bi<- factor(data$bi, labels=c("Bipartisan","Not Bipartisan"))
data$floor2 <- factor(data$floor2, labels=c("Not Overtly Partisan","Overtly Partisan"))

############
# Figure 9A
############

data$dv<-data$Q83
se <- function(x) sd(x, na.rm=T)/sqrt(length(na.omit(x)))
results<- ddply(.data = data, .variables = .(bi,floor2), .fun = summarise, 
				mean = mean(dv, na.rm=T),
				lower = mean(dv, na.rm=T) - (1.96*se(dv)),
				upper = mean(dv, na.rm=T) + (1.96*se(dv)),
				N = length(na.omit(dv)))

(results<-na.omit(results))

k<- qplot(bi,mean,data=results,height=200) +
	geom_errorbar(aes(ymin=lower, ymax=upper),width=.25) + 
	scale_y_continuous(limits = c(4, 7))+
	theme_bw() +
	theme(panel.margin = unit(1, "lines")) + 
	theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.background=element_blank(), axis.title.x = element_text(vjust=-0.5))  + 
	xlab("") + 
	ylab("A) Support for legislation") + 
	coord_flip() +
	facet_grid(.~floor2)
k

ggsave(filename="f9a.eps", plot=k,width=5,height=2)


t.test(data$dv[data$bi=="Bipartisan" & data$floor2=="Not Overtly Partisan"],data$dv[data$bi=="Not Bipartisan"& data$floor2=="Not Overtly Partisan"])
5.245954692556634 - 4.893835616438357 

t.test(data$dv[data$bi=="Bipartisan" & data$floor2!="Not Overtly Partisan"],data$dv[data$bi=="Not Bipartisan" & data$floor2!="Not Overtly Partisan"])
4.750000000000000 - 4.465116279069767 


prop.table(table(data$dv[data$bi=="Not Bipartisan"]))
prop.table(table(data$dv[data$bi=="Bipartisan"]))

############
# Figure 9B
############
#ideology

data$dv<-abs(data$Q84-4)
se <- function(x) sd(x, na.rm=T)/sqrt(length(na.omit(x)))
results<- ddply(.data = data, .variables = .(bi,floor2), .fun = summarise, 
				mean = mean(dv, na.rm=T),
				lower = mean(dv, na.rm=T) - (1.96*se(dv)),
				upper = mean(dv, na.rm=T) + (1.96*se(dv)),
				N = length(na.omit(dv)))

(results<-na.omit(results))

k<- qplot(bi,mean,data=results,height=200) +
	geom_errorbar(aes(ymin=lower, ymax=upper),width=.25) + 
	scale_y_continuous(limits = c(0, 2))+
	theme_bw() +
	theme(panel.margin = unit(1, "lines")) + 
	theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.background=element_blank(), axis.title.x = element_text(vjust=-0.5))  + 
	xlab("") + 
	ylab("B) Absolute distance from Ideological Midpoint") + 
	coord_flip() +
	facet_grid(.~floor2)
k

ggsave(filename="f9b.eps", plot=k,width=5,height=2)

t.test(data$dv[data$bi=="Bipartisan" & data$floor2=="Not Overtly Partisan"],data$dv[data$bi=="Not Bipartisan"& data$floor2=="Not Overtly Partisan"])
0.3527508090614886 -0.7054794520547946 

t.test(data$dv[data$bi=="Bipartisan" & data$floor2!="Not Overtly Partisan"],data$dv[data$bi=="Not Bipartisan" & data$floor2!="Not Overtly Partisan"])
0.7335526315789473 - 0.8039867109634552 


# HET
library(stargazer)
data$pid3 <- relevel(data$pid3, "Independent")
data$bi <- factor(data$bi,levels(data$bi)[c(2,1)])
data$dv<-data$Q83
demsupp <- lm(dv~bi*floor2, data=data[data$pid3=="Republican",])
repsupp <- lm(dv~bi*floor2, data=data[data$pid3=="Democrat",])
data$dv<-abs(data$Q84-4)
demideo <- lm(dv~bi*floor2, data=data[data$pid3=="Republican",])
repideo <- lm(dv~bi*floor2, data=data[data$pid3=="Democrat",])

stargazer(demsupp, repsupp, demideo, repideo,
		  type = "latex", 
		  intercept.bottom = FALSE, 
		  keep.stat = c("rsq"), 
		  digits=2, 
		  star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
		  column.labels =  c("Support (Democrats)","Support (Republicans)", "Extremity (Democrats)", "Extremity (Republicans)"),
		  covariate.labels = c("Intercept", "Bipartisan Treatment", "Overtly Partisan Treatment", "Bipartisan Treatment X Overtly Partisan Treatment"))

data$dv<-data$Q83
demsupp <- lm(dv~bi*floor2, data=data[data$Q4.8<4,])
repsupp <- lm(dv~bi*floor2, data=data[data$Q4.8>4,])
data$dv<-abs(data$Q84-4)
demsupp <- lm(dv~bi*floor2, data=data[data$Q4.8<4,])
repsupp <- lm(dv~bi*floor2, data=data[data$Q4.8>4,])

stargazer(demsupp, repsupp, demideo, repideo,
		  type = "latex", 
		  intercept.bottom = FALSE, 
		  keep.stat = c("rsq"), 
		  digits=2, 
		  star.cutoffs = c(0.1, 0.05, 0.01, 0.001),
		  column.labels =  c("Support (Liberals)","Support (Conservatives)", "Extremity (Liberals)", "Extremity (Conservatives)"),
		  covariate.labels = c("Intercept", "Bipartisan Treatment", "Overtly Partisan Treatment", "Bipartisan Treatment X Overtly Partisan Treatment"))

```

Figure 10 
```{r}
data<-read.csv("figure10.csv",header=T,as.is=T)

dataVotes<-read.csv("votes114.csv",header=T,as.is=T)
dataVotes<-unique(dataVotes[,1:3])

#75.2%
prop.table(table(dataVotes$Answer.dems[dataVotes$Answer.dems<100]<25))
#51.3%
prop.table(table(dataVotes$Answer.dems[dataVotes$Answer.dems<100]<8))
#25.66%
prop.table(table(dataVotes$Answer.dems[dataVotes$Answer.dems<100]<4))

data<-data[data$Q6.2==8,]
## pid3
data$pid3 <-NA
data$pid3[data$Q4.3==1] =1
data$pid3[data$Q4.3==2] =2
data$pid3[data$Q4.3>=3] =3
data$pid3 = factor(data$pid3 , labels=c("Republican","Democrat","Independent"))
table(data$pid3)

df <- read.csv(text="col1,col2")

#age
df<-rbind(df,cbind("Age",round(mean(data$Q1.4+17),digits=2)))
#male
df<-rbind(df,cbind("Male",round(prop.table(table(data$Q1.5))[[1]]*100,digits=2)))
#>college
df<-rbind(df,cbind(">College",round(prop.table(table(data$Q1.6>=7))[[2]]*100,digits=2)))
#white
df<-rbind(df,cbind("White",round(prop.table(table(data$Q1.8==4))[[2]]*100,digits=2)))
#ideology
df<-rbind(df,cbind("Ideology",round(mean(data$Q4.8),digits=2)))
names(df)<-c("Variable"," ")
print(xtable(df),include.rownames=FALSE)

data$condition<-NA
data$condition[data$random<3]<-"Control"
data$condition[data$random<7 & data$random>2]<-"\"Important\" Bill"
data$condition[data$random>6]<-"\"Bipartisan\" Bill"

########### 
# Figure 10
###########

t<-t.test(data$Q2.5[data$condition=="Control"])

e <- ggplot(data[data$condition!="Control",], aes(reps,Q2.5, group=condition, color = condition)) + 
	scale_y_continuous(limits = c(1, 7),expand = c(0, 0)) + 
	scale_x_continuous(limits = c(1, 100),expand = c(0, 0),breaks=seq(0, 100, by=5)) +
	geom_ribbon(aes(ymin=t$conf.int[1],ymax=t$conf.int[2], fill="Partisan Bill\n (0 Democrats)"),alpha=0.8,color=NA) +  
	geom_abline(intercept = t$estimate[[1]], slope = 0,color="#ffffff",alpha=1) +
	ggtitle ("(A)") + stat_smooth(method="loess",aes(fill=condition), alpha=0.6) +
	theme_bw() +
	theme(panel.margin = unit(1, "lines")) + 
	theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.background=element_blank(), axis.title.x = element_text(vjust=-0.5))  + 
	xlab("Number of Democrats Voting for Budget") + 
	ylab("Support for Legislation") + 
	scale_colour_manual(values = c("#ffffff","#ffffff","#ffffff","#000000","#000000"), guide = FALSE) + 
	scale_fill_manual(values = c("#3182bd","#e34a33","#feb24c"),guide = guide_legend(title = "Condition")) + 
	geom_vline(xintercept=c(4,8,25),linetype="dotted",color="#707070") + 
	annotate("text", size=3, x = 5, y = 3.1, label = "25.7% of votes",hjust = 0) +
	annotate("text", size=3, x = 9, y = 3.3, label = "51.3% of votes",hjust = 0) +
	annotate("text", size=3, x = 26, y = 3.5, label = "75.2% of votes",hjust = 0) +
	annotate("segment",x=25,xend=1,y=3.5,yend=3.5,size=0.3,arrow=arrow(length=unit(0.2,"cm"),ends="both",type="closed"),color="#707070") +  
	annotate("segment",x=8,xend=1,y=3.3,yend=3.3,size=0.3,arrow=arrow(length=unit(0.2,"cm"),ends="both",type="closed"),color="#707070") +  
	annotate("segment",x=4,xend=1,y=3.1,yend=3.1,size=0.3,arrow=arrow(length=unit(0.2,"cm"),ends="both",type="closed"),color="#707070") +
	coord_cartesian(ylim=c(3,6)) +
	theme(legend.position="bottom")
e

ggsave(filename="f10a.pdf", plot=e,width=6.5,height=5)


m<-lm(Q2.5~reps,data=data[data$condition=="\"Bipartisan\" Bill",])
eff<-effect(m,term="reps",se=T,xlevels=list(x1=c(1,100)))

dataeff<-as.data.frame(eff)
dataeff<-dataeff[c(1,5),]
dataeff

datacontrol<-as.data.frame(cbind(0,t$estimate[[1]],0,t$conf.int[1],t$conf.int[2]))
names(datacontrol)<-names(dataeff)
dataeff<-rbind(dataeff,datacontrol)

4.5/3.98
4.76/4.5
(4.76-4.5)/99

dataeff$reps <- factor(dataeff$reps, labels=c("Partisan Bill\n (0 Democrats)","\"Bipartisan\" Bill \n+ 1 Democrat","\"Bipartisan\" Bill \n+ 100 Democrats"))

d<- qplot(reps,fit,data=dataeff,color=reps,height=200) +
	geom_errorbar(aes(ymin=lower, ymax=upper),width=.25) + 
	coord_cartesian(ylim=c(3,6)) +
	theme_bw() +
	ggtitle("(B)")+
	theme(panel.margin = unit(1, "lines")) + 
	theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.background=element_blank(), axis.title.x = element_text(vjust=-0.5))  + 
	xlab("") + 
	ylab("") + 
	scale_color_manual(values = c("#feb24c","#3182bd","#3182bd"),guide = FALSE) +
	theme(axis.text.x = element_text(angle = 90, hjust = 1),axis.text.y=element_blank()) +
	theme(plot.margin = unit(c(.475, .25, 0, -.5), "cm")) +
	annotate("segment",x=1.5,xend=1.5,y=dataeff$fit[3],yend=dataeff$fit[1],size=0.3,color="#707070") +
	annotate("segment",x=1.5,xend=1,y=dataeff$fit[3],yend=dataeff$fit[3],size=0.3,color="#707070") +
	annotate("segment",x=1.5,xend=1.95,y=dataeff$fit[1],yend=dataeff$fit[1],size=0.3,arrow=arrow(length=unit(0.2,"cm"),type="closed"),color="#707070") +
	annotate("segment",x=2.5,xend=2.5,y=dataeff$fit[2],yend=dataeff$fit[1],size=0.3,color="#707070") +
	annotate("segment",x=2.5,xend=2,y=dataeff$fit[1],yend=dataeff$fit[1],size=0.3,color="#707070") +
	annotate("segment",x=2.5,xend=2.95,y=dataeff$fit[2],yend=dataeff$fit[2],size=0.3,arrow=arrow(length=unit(0.2,"cm"),type="closed"),color="#707070") +
	annotate("text", size=3, x = 1.2, y = 3.6, label = paste(round(((dataeff$fit[1]/dataeff$fit[3])-1)*100, digits=2), "%\nmore \nsupport",sep=""),hjust = 0) +
	annotate("text", size=3, x = 2.2, y = 4.58, label = paste(round(((dataeff$fit[2]/dataeff$fit[1])-1)*100, digits=2), "%\nmore \nsupport",sep=""),hjust = 0) 


d

ggsave(filename="f10b.eps", plot=d,width=2,height=5.22)


t<-t.test(data$Q2.5[data$condition=="Control"], data$Q2.5[data$condition=="\"Bipartisan\" Bill" & data$reps==1])
#WHAT DOES THIS MEAN??? WHAT IS THE ERROR? WHY?

```
#ERROR IN T-TEST 

Figure 11
```{r}
########### 
# Figure 11
###########

t2<-t.test(data$Q2.6[data$condition=="Control"])

e2 <- ggplot(data[data$condition!="Control",], aes(reps,Q2.6, group=condition, color = condition)) + 
	scale_y_continuous(limits = c(1, 7),expand = c(0, 0)) + 
	scale_x_continuous(limits = c(1, 100),expand = c(0, 0),breaks=seq(0, 100, by=5)) +
	geom_ribbon(aes(ymin=t2$conf.int[1],ymax=t2$conf.int[2], fill="Partisan Bill\n (0 Democrats)"),alpha=0.8,color=NA) +  
	geom_abline(intercept = t2$estimate[[1]], slope = 0,color="#ffffff",alpha=1) +
	ggtitle ("(A)") + stat_smooth(method="loess",aes(fill=condition), alpha=0.6) +
	theme_bw() +
	theme(panel.margin = unit(1, "lines")) + 
	theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.background=element_blank(), axis.title.x = element_text(vjust=-0.5))  + 
	xlab("Number of Democrats Voting for Budget") + 
	ylab("Legislaton's Ideological Placement") + 
	scale_colour_manual(values = c("#ffffff","#ffffff","#ffffff","#000000","#000000"), guide = FALSE) + 
	scale_fill_manual(values = c("#3182bd","#e34a33","#feb24c"),guide = guide_legend(title = "Condition")) + 
	geom_vline(xintercept=c(4,8,25),linetype="dotted",color="#707070") + 
	annotate("text", size=3, x = 5, y = 3.1, label = "25.7% of votes",hjust = 0) +
	annotate("text", size=3, x = 9, y = 3.3, label = "51.3% of votes",hjust = 0) +
	annotate("text", size=3, x = 26, y = 3.5, label = "75.2% of votes",hjust = 0) +
	annotate("segment",x=25,xend=1,y=3.5,yend=3.5,size=0.3,arrow=arrow(length=unit(0.2,"cm"),ends="both",type="closed"),color="#707070") +  
	annotate("segment",x=8,xend=1,y=3.3,yend=3.3,size=0.3,arrow=arrow(length=unit(0.2,"cm"),ends="both",type="closed"),color="#707070") +  
	annotate("segment",x=4,xend=1,y=3.1,yend=3.1,size=0.3,arrow=arrow(length=unit(0.2,"cm"),ends="both",type="closed"),color="#707070") +
	coord_cartesian(ylim=c(3,6)) +
	theme(legend.position="bottom")
e2

ggsave(filename="f11a.pdf", plot=e2,width=6.5,height=5)

m2<-lm(Q2.6~reps,data=data[data$condition=="\"Bipartisan\" Bill",])

eff2<-effect(m2,term="reps",se=T,default.levels=100)


dataeff2<-as.data.frame(eff2)
dataeff2<-dataeff2[c(1,5),]


(5.09-4.83)/99

datacontrol2<-as.data.frame(cbind(0,t2$estimate[[1]],0,t2$conf.int[1],t2$conf.int[2]))
names(datacontrol2)<-names(dataeff2)
dataeff2<-rbind(dataeff2,datacontrol2)

(dataeff2$fit[2]-dataeff2$fit[1])/99

dataeff2$reps <- factor(dataeff2$reps, labels=c("Partisan Bill\n (0 Democrats)","\"Bipartisan\" Bill \n+ 1 Democrat","\"Bipartisan\" Bill \n+ 100 Democrats"))

d2<- qplot(reps,fit,data=dataeff2,color=reps,height=200) +
	geom_errorbar(aes(ymin=lower, ymax=upper),width=.25) + 
	coord_cartesian(ylim=c(3,6)) +
	theme_bw() +
	ggtitle("(B)")+
	theme(panel.margin = unit(1, "lines")) + 
	theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(),panel.background=element_blank(), axis.title.x = element_text(vjust=-0.5))  + 
	xlab("") + 
	ylab("") + 
	scale_color_manual(values = c("#feb24c","#3182bd","#3182bd"),guide = FALSE) +
	theme(axis.text.x = element_text(angle = 90, hjust = 1),axis.text.y=element_blank()) +
	theme(plot.margin = unit(c(.475, .25, 0, -.5), "cm")) +
	annotate("segment",x=1.5,xend=1.5,y=dataeff2$fit[3],yend=dataeff2$fit[1],size=0.3,color="#707070") +
	annotate("segment",x=1.5,xend=1,y=dataeff2$fit[3],yend=dataeff2$fit[3],size=0.3,color="#707070") +
	annotate("segment",x=1.5,xend=1.95,y=dataeff2$fit[1],yend=dataeff2$fit[1],size=0.3,arrow=arrow(length=unit(0.2,"cm"),type="closed"),color="#707070") +
	annotate("segment",x=2.5,xend=2.5,y=dataeff2$fit[2],yend=dataeff2$fit[1],size=0.3,color="#707070") +
	annotate("segment",x=2.5,xend=2,y=dataeff2$fit[1],yend=dataeff2$fit[1],size=0.3,color="#707070") +
	annotate("segment",x=2.5,xend=2.95,y=dataeff2$fit[2],yend=dataeff2$fit[2],size=0.3,arrow=arrow(length=unit(0.2,"cm"),type="closed"),color="#707070") +
	annotate("text", size=3, x = .7, y = 4.24, label = paste(round(((dataeff2$fit[1]/dataeff2$fit[3])-1)*-100, digits=2), "%\nless \nconservative",sep=""),hjust = 0) +
	annotate("text", size=3, x = 2.2, y = 3.86, label = paste(round(((dataeff2$fit[2]/dataeff2$fit[1])-1)*-100, digits=2), "%\nless \nconservative",sep=""),hjust = 0) 


d2

ggsave(filename="f11b.eps", plot=d2,width=2,height=5.22)

```
